package com.example.myapplication;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {
    MediaPlayer mediaPlayer;
    Context context;


    public MyService() {
        context=this;
        Log.d("king","MyService");

    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.d("king","MyService onStartCommand...");


        mediaPlayer=MediaPlayer.create(this,R.raw.music1);
        mediaPlayer.start();
        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public IBinder onBind(Intent intent) {//Binder类

        // TODO: Return the communication channel to the service.
        //throw new UnsupportedOperationException("Not yet implemented");
        Mybinder binder=new Mybinder();
        return binder;

    }

    @Override
    public void onDestroy() {

        Log.d("king","MyService onDestroy...");
        mediaPlayer.stop();
        super.onDestroy();
    }
    public class Mybinder extends Binder{
        public Mybinder(){

        }
        public void todo(){
            Log.d("king","MyService onDestroy...");
            mediaPlayer=MediaPlayer.create(context,R.raw.music1);
            mediaPlayer.start();
        }



    }


}